package czy.demo.endpoint;

import org.springframework.boot.actuate.endpoint.web.EndpointServlet;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.function.Supplier;

/** servlet端点 */
@Component
@ServletEndpoint(id="servlet")
public class DefaultServletEndpointSupplier implements Supplier {

    @Override
    public Object get() {
        return new EndpointServlet(new DefaultEndpointServlet());
    }

    public static class DefaultEndpointServlet implements Servlet{
        @Override
        public void init(ServletConfig config) throws ServletException {

        }

        @Override
        public ServletConfig getServletConfig() {
            return null;
        }

        @Override
        public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
            res.setCharacterEncoding("UTF-8");
            res.getWriter().println("这是一个servlet端点");
        }

        @Override
        public String getServletInfo() {
            return null;
        }

        @Override
        public void destroy() {

        }
    }
}
